


project , uses("constituency_elections.dta")
project , uses("candidate_elections.dta")


	
	
foreach v in   spending_total_adj candidates effective_candidates effective_spenders  inc_spending_pct inc_vote_pct     { // 

		use "constituency_elections.dta", clear //open data

		replace spending_limit_predicted_adj = log(10*spending_limit_predicted_adj) // linear-log model
		label var spending_limit_predicted_adj "Log Spending Limit"
		estimates clear
	
		eststo: reg   `v'   spending_limit_predicted_adj  ,  cluster(const_id) 
		estadd scalar  Observations = e(N)
		estadd scalar  Constituencies = e(N_clust)	
				
		eststo: reg   `v'   spending_limit_predicted_adj  county electors countyXelectors ,  cluster(const_id) 
		estadd scalar  Observations = e(N)	
		estadd scalar  Constituencies = e(N_clust)	
					
		eststo: reghdfe   `v'   spending_limit_predicted_adj  county  countyXelectors , a( date date#c.electors ) cluster(const_id) keepsingletons
		estadd scalar  Observations = e(N)	
		estadd scalar  Constituencies = e(N_clust)	
					
		eststo: reghdfe   `v'   spending_limit_predicted_adj   countyXelectors , a( date date#c.electors const_id ) cluster(const_id) keepsingletons
		estadd scalar  Observations = e(N)					
		estadd scalar  Constituencies = e(N_clust)	
		
		esttab  using ./tables/`v'_loglimit.tex ///
		,  replace   keep(spending_limit_predicted_adj  ) label se nostar  nomtitles  nolines ///
		substitute("%" "\%"  "Observations" "\midrule Observations" "\hline" "\midrule" N_clust "Constituencies" "[1em]" "") noobs  nonum fragment scalar(Observations  Constituencies) b(%4.2f) sfmt(  %9.0fc  %9.0fc   ) ///
		mgroups("`: var la `v''"  , pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
		
		project , creates("tables/`v'_loglimit.tex")			
		
}
		
	

		
	***incumbency advantage & spending limits: spending and vote shares
	use "candidate_elections.dta", clear //open data
	replace spending_limit_predicted_adj = log(10*spending_limit_predicted_adj) // linear-log model	
	replace incXspending_limit_predicted_adj = inc*spending_limit_predicted_adj // linear-log model	

	label var spending_limit_predicted_adj "Log Spending Limit"
	label var incXspending_limit_predicted_adj "Incumbent $\times$ Log Spending Limit"
	
	
	eststo clear
	
	eststo: reghdfe spending_pct inc  , a( cand_id party_election) cluster(const_id) keepsingletons
	estadd scalar  Observations = e(N)		
	eststo: reghdfe spending_pct inc incXspending_limit_predicted_adj   spending_limit_predicted_adj , a( cand_id party_election ) cluster(const_id)  keepsingletons
	estadd scalar  Observations = e(N)	
		
	eststo: reghdfe vote_pct inc  , a( cand_id party_election) cluster(const_id) keepsingletons
	estadd scalar  Observations = e(N)		
	eststo: reghdfe vote_pct inc incXspending_limit_predicted_adj   spending_limit_predicted_adj , a( cand_id party_election ) cluster(const_id)  keepsingletons
	estadd scalar  Observations = e(N)	
	
	esttab  using ./tables/incumbency_loglimit.tex ///
	,  replace   keep(inc  incXspending_limit_predicted_adj   spending_limit_predicted_adj   ) label se nostar noobs nomtitles nonumbers nolines ///
	substitute( "StDev" "St. Dev." "Observations" "\midrule Observations" "\hline" "\midrule" N_clust "Constituencies" "[1em]" "") compress  fragment scalar(Observations  ) b(%4.2f) sfmt(  %9.0fc  %9.0fc %9.2fc  ) ///
	mgroups("\% Spending" "\% Votes" , pattern(1 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
	project , creates("tables/incumbency_loglimit.tex")	
	
	
	
	*candidate-level difference-in-difference estimates by party
	use "candidate_elections.dta", clear //open data
	eststo clear
	replace spending_limit_predicted_adj = log(10*spending_limit_predicted_adj) // linear-log model	
	replace labXlimit = lab*spending_limit_predicted_adj
	replace libXlimit = lib*spending_limit_predicted_adj
	replace otherXlimit = other*spending_limit_predicted_adj

	label var spending_limit_predicted_adj "Log Spending Limit"
	label var labXlimit "Log Spending Limit $\times$ Labour"
	label var libXlimit "Log Spending Limit $\times$ Liberal (Dem.)"
	label var otherXlimit "Log Spending Limit $\times$ Other"
	
	
	
	foreach v in spending_total_adj spending_pct vote_pct   {
		eststo: reghdfe `v' spending_limit_predicted_adj labXlimit  libXlimit otherXlimit    , a( cand_id party_election ) cluster(const_id) keepsingletons
		estadd scalar  Observations = e(N)	
		
		esttab  using ./tables/party_loglimit.tex ///
		,  replace   keep( spending_limit_predicted_adj labXlimit  libXlimit otherXlimit    ) label se nostar noobs nomtitles nonumbers nolines ///
		substitute( "StDev" "St. Dev." "Observations" "\midrule Observations" "\hline" "\midrule" N_clust "Constituencies" "[1em]" "") compress  fragment scalar(Observations  ) b(%4.2f) sfmt(  %9.0fc  %9.0fc %9.2fc  ) ///
		mgroups("Spending" "\% Spending" "\% Votes" , pattern(1 1 1 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
		
	}	
	project , creates("tables/party_loglimit.tex")	
	
	
	
	
	
	
